package com.xinfu.newproject.presenter;

import com.xinfu.newproject.bean.login.LoginBean;
import com.xinfu.newproject.bean.login.LoginBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.login.LoginModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class LoginPresenter {
    private IView.ILoginView mILoginView;

    private LoginModel mLoginModel;

    public LoginPresenter(IView.ILoginView iLoginView) {
        this.mILoginView = iLoginView;
        mLoginModel = new LoginModel();
    }

    /**
     * 登录
     */
    public void login() {

        mILoginView.showProgress();

        LoginBody loginBody = new LoginBody(mILoginView.getUserName(), mILoginView.getPassword());

        mLoginModel.login(loginBody, new MyCallBack<LoginBean>() {
            @Override
            public void onSuccess(LoginBean loginBean) {
                mILoginView.hideProgress();
                if (loginBean.isSuccess()) {
                    mILoginView.toOtherActivity(loginBean);
                } else {
                    mILoginView.showToast(loginBean.getMessage());
                }
            }

            @Override
            public void onError(String header, String message) {
                mILoginView.hideProgress();
                mILoginView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mILoginView.closeDispose(disposable);
            }
        });


    }


//    private Map<String, String> createParaMap() {
//        Map<String, String> paraMap = new HashMap<>();
//        paraMap.put("userName", mIRegisterView.getUserName());
//        return paraMap;
//    }

}
